<?php

namespace app\helpers;

use yii;

/**
 * Class sendEmailHelper
 * @package app\helpers
 */
class sendEmailHelper extends yii\helpers\StringHelper
{
    /**
     * @param $to array|string 收件人地址
     * @param $subject 邮件主题
     * @param $html 邮件内容
     * @return string
     */
    public static function sendEmail($to, $subject, $html)
    {
        $url = 'http://api.sendcloud.net/apiv2/mail/send';
        //lv
        $API_USER = 'asovip_test_fM2Rwa';
        $API_KEY = 'mOqEFHTgFp437bQ0';
        //cb
//        $API_USER = 'chengjisihan_test_7kLMSi';
//        $API_KEY = 'wO1Yik0226wDZVGl';

        $param['apiUser'] = $API_USER;
        $param['apiKey'] = $API_KEY;
        $param['from'] = 'admin@jukamedia.com';
        $param['fromName'] = 'juka';
        $param['respEmailId'] = 'true';
        $param['subject'] = $subject;
        $param['html'] = $html;

        if (is_array($to)) {
            $param['to'] = implode(';', $to);
        } else {
            $param['to'] = $to;
        }

        $data = http_build_query($param);

        $options = array(
            'http' => array(
                'method' => 'POST',
                'header' => 'Content-Type: application/x-www-form-urlencoded',
                'content' => $data
            ));
        $context  = stream_context_create($options);
        $result = file_get_contents($url, FILE_TEXT, $context);

        return $result;
    }

}
